from qq_music_text.items import QqMusicTextItem
import scrapy


class File1Spider(scrapy.Spider):
    name = 'file_1'
    allowed_domains = ['y.qq.com']
    start_urls = ['https://y.qq.com/n/ryqq/category']

    def parse(self, response):
        #new一个Item对象
        item = QqMusicTextItem()
        lis = response.xpath("/html/body/div/div/div[2]/div[2]/div[2]/ul/li")
        for li in lis:
            item['author'] = li.xpath('./div/div[2]/a/text()').extract()[0]
            item['title'] = li.xpath('./div/h4/span/a/text()').extract()[0]
            item['bofangliang'] = li.xpath('./div/div[3]/text()').extract()[0]
            item['image_url'] = li.xpath('./div/div/a/img/@src').extract()[0]
            # item['标题'] = ''
            yield item

        #翻页功能
        # if response.xpath("//*[@class='next']"):
        #     next_page_url = response.xpath(
        #         "//*[@class='next']/@href").extract()[0]
        #     #回调parse方法
        #     yield scrapy.Request(next_page_url, callback=self.parse)


